package com.im.service;


import com.im.dao.ColumnDao;
import com.im.pojo.Column;
import com.im.pojo.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.UUID;
@Service
public class CloumnSrvImpl implements ColumnService{

    @Autowired
    private ColumnDao columnDao;

    public int save(Column column, User user) {
        String uuid = UUID.randomUUID().toString().replace("-", "");
        Date date = new Date();
        column.setId(uuid);
        column.setCreateTime(date);
        column.setModifyTime(date);
        column.setUserId(user.getId());
       return columnDao.save(column);
    }

    public int delete(Column column,User user)  {

        Date date = new Date();
        column.setIsDel(1);//是否删除 1---删除 改他ColumnMapper.xml也需要改
        column.setUserId(user.getId());
        column.setModifyTime(date);
        return columnDao.deleteById(column);

    }

    public int update(Column column,User user)  {
        Date date = new Date();
        column.setModifyTime(date);
        column.setUserId(user.getId());
        int num = columnDao.updateById(column);
        return num;

    }

    public Column query(Column column)  {

        column = columnDao.queryById(column);

            return column;


    }

    public List queryAll(Column column,User user) {
        column.setUserId(user.getId());
        if (column.getName() != null && !"".equals(column.getName())) {//java中判断是不是字符串!"".equals(column.getName())XML里判断是不是字符串and name!=''
            column.setName("%"+column.getName()+"%");
        }
        List list = columnDao.queryAll(column);
            return list;
    }
}
